package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
)

type student struct {
	Name string
	Age  int
	Sex  string
}

func (s *student) Save() (err error) {
	data, err := json.Marshal(s)
	if err != nil {
		fmt.Println("json失败")
		return
	}
	err = ioutil.WriteFile("C:\\stu.data", data, 0755)
	return
}

func (s *student) Load() (err error){
	data , err := ioutil.ReadFile("C:\\stu.data")
	if err != nil {
		return
	}
	err = json.Unmarshal(data, s)
	return
}
